package proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by liuweijie on 2018/4/24.
 */
public class QianTaiGirl implements InvocationHandler {

    private Person target;

    public Object getInstance(Person target){
        this.target=target;
        Class<? extends Person> clazz = target.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);

    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("前台：有什么可以帮到您？");
        method.invoke(target,args);
        System.out.println("前台：已经买好，给你");
        System.out.println("前台：我先离开，有事再找我");
        return null;
    }
}
